package com.zgg.utils.aliOss;

import com.zgg.enums.AliOssImageEnum;

/**
 * Created by Administrator on 2017/9/18 0018.
 */

     /*
                           _ooOoo_
                          o8888888o
                          88" . "88
                          (| -_- |)
                          O\  =  /O
                       ____/`---'\____
                     .'  \\|     |//  `.
                    /  \\|||  :  |||//  \
                   /  _||||| -:- |||||-  \
                   |   | \\\  -  /// |   |
                   | \_|  ''\---/''  |   |
                   \  .-\__  `-`  ___/-. /
                 ___`. .'  /--.--\  `. . __
              ."" '<  `.___\_<|>_/___.'  >'"".
             | | :  `- \`.;`\ _ /`;.`/ - ` : | |
             \  \ `-.   \_ __\ /__ _/   .-` /  /
        ======`-.____`-.___\_____/___.-`____.-'======
                           `=---='
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 佛祖保佑       永无BUG
        */
public class AliOssImageResize extends AbstractAliOssImage {

    /**
     * 压缩处理
     *
     * @param aliOssImageConfig
     * @return
     */
    @Override
    public String operatingString(AliOssImageConfig aliOssImageConfig) {
        StringBuffer sb = new StringBuffer();
        sb.append(imageStyle);
        sb.append(AliOssImageEnum.ALI_HANDLE_RESIZE.getValue());
        //验证参数的正确性
        if (aliOssImageConfig.getProportion() > 0 && valiArgs(aliOssImageConfig.getProportion(), 1, 100)) {
            sb.append(",p_").append(aliOssImageConfig.getProportion());
        } else {
            if (aliOssImageConfig.getResizeType() != 0) {
                sb.append(",m").append(AliOssImageEnum.getAliOssImageResizeType(aliOssImageConfig.getResizeType()));
            }
            if (valiArgs(aliOssImageConfig.getHeight(), 1, 4096))
                sb.append(",h_").append(aliOssImageConfig.getHeight());
            if (valiArgs(aliOssImageConfig.getWidth(), 1, 4096))
                sb.append(",w_").append(aliOssImageConfig.getWidth());
        }
        return sb.toString();
    }
}
